include:
  - openstack.queen.mariadb.install

openstack-db-user-grant:
  file.managed:
    - name: /etc/script/openstack-db.sh
    - source: salt://openstack/queen/mariadb/files/openstack-db.sh
    - user: root
    - group: root
    - mode: 744
    - template: jinja
    - defaults:
      ROOT_PASS: {{ pillar['mysql']['ROOT_PASS'] }}
#keystone
      KEYSTONE_DB_NAME: {{ pillar['keystone']['KEYSTONE_DB_NAME'] }}
      KEYSTONE_DB_USER: {{ pillar['keystone']['KEYSTONE_DB_USER'] }}
      KEYSTONE_DB_PASS: {{ pillar['keystone']['KEYSTONE_DB_PASS'] }}
      KEYSTONE_HOST_ALLOW : {{ pillar['keystone']['KEYSTONE_HOST_ALLOW'] }}
#glance
      GLANCE_DB_NAME: {{ pillar['glance']['GLANCE_DB_NAME'] }}
      GLANCE_DB_USER: {{ pillar['glance']['GLANCE_DB_USER'] }}
      GLANCE_DB_PASS: {{ pillar['glance']['GLANCE_DB_PASS'] }}
      GLANCE_HOST_ALLOW : {{ pillar['glance']['GLANCE_HOST_ALLOW'] }}
#nova
      NOVA_DB_NAME: {{ pillar['nova']['NOVA_DB_NAME'] }}
      NOVA_API_DB_NAME: {{ pillar['nova']['NOVA_API_DB_NAME'] }}
      NOVA_CELL0_DB_NAME: {{ pillar['nova']['NOVA_CELL0_DB_NAME'] }}
      NOVA_DB_USER: {{ pillar['nova']['NOVA_DB_USER'] }}
      NOVA_DB_PASS: {{ pillar['nova']['NOVA_DB_PASS'] }}
      NOVA_HOST_ALLOW : {{ pillar['nova']['NOVA_HOST_ALLOW'] }}
#neutron
      NEUTRON_DB_NAME: {{ pillar['neutron']['NEUTRON_DB_NAME'] }}
      NEUTRON_DB_USER: {{ pillar['neutron']['NEUTRON_DB_USER'] }}
      NEUTRON_DB_PASS: {{ pillar['neutron']['NEUTRON_DB_PASS'] }}
      NEUTRON_HOST_ALLOW : {{ pillar['neutron']['NEUTRON_HOST_ALLOW'] }}
#cinder
      CINDER_DB_NAME: {{ pillar['cinder']['CINDER_DB_NAME'] }}
      CINDER_DB_USER: {{ pillar['cinder']['CINDER_DB_USER'] }}
      CINDER_DB_PASS: {{ pillar['cinder']['CINDER_DB_PASS'] }}
      CINDER_HOST_ALLOW : {{ pillar['cinder']['CINDER_HOST_ALLOW'] }}
  cmd.run:
    - name: bash /etc/script/openstack-db.sh && touch /etc/lock/openstack-db.lock
    - unless: test -f /etc/lock/openstack-db.lock
    - require:
      - cmd: mariadb-secure-install
